package java_thinking.unit_15._15_15;

/**
 * @Description :   装饰器模式
 *                  https://www.cnblogs.com/jenkinschan/p/5683099.html
 * @author: cww
 * @DateTime: 2019-04-07 20:53
 */

class Basic1 {
    private String value;
    public void set(String val) {
        value = val;
    }
    public String get() {
        return value;
    }
}

public class Decorator extends Basic1 {
    protected Basic1 basic;
    public Decorator(Basic1 basic) {
        this.basic = basic;
    }
    @Override
    public void set(String val) {
        basic.set(val);
    }
    @Override
    public String get() {
        return basic.get();
    }
}

class TimeStamped1 extends Decorator {
    private final long timeStamp;
    public TimeStamped1(Basic1 basic) {
        super(basic);
        timeStamp = System.currentTimeMillis();
    }
    public long getStamp() {
        return timeStamp;
    }
}
class SerialNumbered1 extends Decorator {
    private static long counter = 1;
    private final long serialNumber = counter++;
    public SerialNumbered1(Basic1 basic1) {
        super(basic1);
    }
    public long getSerialNumber() {
        return serialNumber;
    }
}

class Decoration {
    public static void main(String[] args) {
        TimeStamped1 t = new TimeStamped1(new Basic1());
        TimeStamped1 t2 = new TimeStamped1(new SerialNumbered1(new Basic1()));
        //! t2.getSerialNumber();
        SerialNumbered1 s = new SerialNumbered1(new Basic1());
        SerialNumbered1 s2 = new SerialNumbered1(new TimeStamped1(new Basic1()));
        //! s2.getStamp();
    }
}